import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import { getBanners } from "../service/recommend";

export const fetchBannersDateAction = createAsyncThunk("banners", async (arg, { dispatch, getState }) => {
  const res = await getBanners();
  console.log(res);
  dispatch(changeBannersAction(res.banners));
  //   return res.banners;
});

interface IRecommendState {
  banners: any[];
  hotRecommends: any[];
  newAlbums: any[];
}
const initialState: IRecommendState = {
  banners: [],
  hotRecommends: [],
  newAlbums: [],
};

const recommendSlice = createSlice({
  name: "banners",
  initialState,
  reducers: {
    changeBannersAction(state, { payload }) {
      state.banners = payload;
    },
  },
  extraReducers(builder) {
    // builder.addCase(fetchBannersDateAction.pending, (state, action) => {});
    // builder.addCase(fetchBannersDateAction.fulfilled, (state, { payload }) => {
    //   state.banners = payload;
    // });
    // builder.addCase(fetchBannersDateAction.rejected, (state, action) => {});
  },
});
export const { changeBannersAction } = recommendSlice.actions;
export default recommendSlice.reducer;
